# -*- coding: utf-8 -*-

# Scrapy settings for baidusolu project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html
import os

BOT_NAME = 'baidusolu'

EXPORT_ORIGIN_DIR = '/home/scrapy/baidusolu/export/origin/'
EXPORT_CLEAN_DIR = '/home/scrapy/baidusolu/export/clean/'
EXPORT_SQL_DIR = '/home/scrapy/baidusolu/export/sql/'

SPIDER_MODULES = ['baidusolu.spiders']
NEWSPIDER_MODULE = 'baidusolu.spiders'

CRAWLERA_ENABLED = True
CRAWLERA_USE = '0edfb2f6693e4c92be7897f3a799e32a'
CRAWLERA_PASS = ''

MYSQL_HOST = 'localhost'
MYSQL_DB = 'kameng'
MYSQL_USER = 'ka'
MYSQL_PASSWORD = 'kameng98666'
# MYSQL_HOST = '192.168.0.149'
# MYSQL_DB = 'credit'
# MYSQL_USER = 'root@172.17.0.2'
# MYSQL_PASSWORD = 'root'
MYSQL_PORT = '3306'
MYSQL_CHARSET = 'utf8mb4'

CONCURRENT_REQUESTS = 32
CONCURRENT_REQUESTS_PER_DOMAIN = 32
AUTOTHROTTLE_ENABLED = False
DOWNLOAD_TIMEOUT = 600

DOWNLOAD_DELAY = 1
RANDOMIZE_DOWNLOAD_DELAY = True

# CLOSESPIDER_ERRORCOUNT = 1

DOWNLOAD_MIDDLEWARES = {
    'scrapy_crawlera.CrawleraMiddleWares': 600
}

DOWNLOADER_MIDDLEWARES = {
    'baidusolu.middlewares.RandomUserAgentMiddleware': 543,
    'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
}

DEFAULT_REQUEST_HEADERS = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate, sdch',
    'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Host': 'www.baidu.com',
    'RA-Sid': '7739A016-20140918-030243-3adabf-48f828',
    'RA-Ver': '3.0.7',
    'Upgrade-Insecure-Requests': '1',
    'Cookie': '2k3dzlrdUFhTHpVQmNnS2VXRkozR3J6cTFlWGItRHBDOX4zVEtPcHNOMUhJTEplSVFBQUFBJCQAAAAAAAAAAAEAAACA5OAuX-Cp0arC3MDyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEeTil5Hk4peT'
}

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
    'baidusolu.pipelines.BaidusoluPipeline': 300,
}

# Crawl responsibly by identifying yourself (and your website) on the user-agent
# USER_AGENT = 'tutorial (+http://www.yourdomain.com)'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False
# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'baidusolu (+http://www.yourdomain.com)'

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
#COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False

# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'en',
#}

# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'baidusolu.middlewares.BaidusoluSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
#    'baidusolu.middlewares.BaidusoluDownloaderMiddleware': 543,
#}

# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
#    'baidusolu.pipelines.BaidusoluPipeline': 300,
#}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
